import 'package:flutter/material.dart';
import './divider.dart';
import './border.dart';

class BottomSheetItem {
  final Widget child;
  final VoidCallback onTap;

  BottomSheetItem({
    required this.child,
    required this.onTap
  });
}

// 封装的 showMyBottomSheet 方法
void showMyBottomSheet(BuildContext context, List<BottomSheetItem> items) {
  showModalBottomSheet(
    backgroundColor: Colors.white,
    context: context,
    builder: (BuildContext context) {
      return Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          ...items.map((sheetItem) => Column(
            children: [
              ListTile(
                title: Center(child: sheetItem.child),
                onTap: () {
                  Navigator.pop(context); // 先出栈，再执行点击回调
                  sheetItem.onTap();
                },
              ),
              const DividerLine()
            ],
          )),
          const BorderBox(
            color: Color(0xFFF7F7F7),
          ),
          ListTile(
            title: const Center(child: Text('取消')),
            onTap: () {
              Navigator.pop(context);
            },
          )
        ],
      );
    },
  );
}